package com.ymatou.app.api.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.api.parameter.DeleteAddressBean;
import com.ymatou.app.api.service.DeleteAddressCall;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.business.service.YmtCallService;
import com.ymttest.utils.constant.ECode;

/**
 * 删除收货地址 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DeleteAddress {
	private static DeleteAddressBean deladdressbean;
	private static DeleteAddressCall deladdresscall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除收货地址");
	}

	@Before
	public void caseUp() {
		deladdressbean = new DeleteAddressBean();
		deladdresscall = new DeleteAddressCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deladdresscall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeleteAddress_001() {
		Logger.start(true,"删除收货地址成功");
		try {
			// String UserName = "13511867828";
			String PassWord = "123456";
			// 注册获取token和userid
			
			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			// 登录获取token和userid
			/*
			 * YmtCallService ymt = new YmtCallService(); Map<?, ?> User =
			 * ymt.appLogin(); String AccessToken = (String)
			 * User.get("AccessToken"); int UserId = (Integer)
			 * User.get("UserId");
			 */
			// 制造一条数据
			YmtCallService ymt = new YmtCallService();
			ymt.addAddress(AccessToken, UserId);
			List AddressIdList = ymt.getAddressId(AccessToken, UserId);
			// 设置数据
			Integer AddressId = (Integer) AddressIdList.get(0);
			deladdressbean.setAddressId(AddressId);
			Logger.comment("删除的地址ID:" + AddressId);
			deladdressbean.setUserId(UserId);
			Logger.comment("UserId:" + UserId);
			deladdressbean.setAccessToken(AccessToken);
			Logger.comment("AccessToken:" + AccessToken);
			// 发送数据
			deladdresscall.setData(deladdressbean);
			deladdresscall.callService();
			// Logger.debug(deladdresscall.getReturnData());
			Logger.comment("deladdresscall send:" + deladdresscall.getEntityString());
			Logger.comment("deladdresscall response:" + deladdresscall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, deladdresscall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE0, deladdresscall.getBCode(), "验证BCode");
			Logger.verifyEquals(ECode.APP_MSG1, deladdresscall.getMsg(), "验证消息");
			Logger.verifyEquals(true, deladdresscall.getResult(), "验证result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}